package kama;

import java.util.*;
import java.util.stream.Collectors;

public class Test0107 {
}

class Main0107_1{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] split;

        split= scanner.nextLine().split(" ");
        int m = Integer.parseInt(split[0]);
        int n = Integer.parseInt(split[1]);

        boolean[] record = new boolean[m+1];
        HashMap<Integer, List<Integer>> map = new HashMap<>();

        for(int i=0;i<n;i++){
            split = scanner.nextLine().split(" ");
            int key1 = Integer.parseInt(split[0]);
            int key2 = Integer.parseInt(split[1]);

            List<Integer> list = map.getOrDefault(key1, new ArrayList<>());
            list.add(key2);
            map.put(key1, list);

            List<Integer> list1 = map.getOrDefault(key2, new ArrayList<>());
            list1.add(key1);
            map.put(key2, list1);
        }

        split = scanner.nextLine().split(" ");
        int start = Integer.parseInt(split[0]);
        int end = Integer.parseInt(split[1]);

        ArrayDeque<Integer> deque = new ArrayDeque<>();
        deque.add(start);
        record[start]=true;
        int size = deque.size();

        while (size>0) {
            for (int i = 0; i < size; i++) {
                List<Integer> list = map.get(deque.poll());
                if (list!=null) {
                    for (Integer integer : list) {
                        if (!record[integer]) {
                            record[integer] = true;
                            deque.offer(integer);
                        }
                    }
                }

                if (record[end]){
                    System.out.println(1);
                    return;
                }
                size=deque.size();
            }
        }

        System.out.println(0);
    }
}
